<template>
  <div class="menu-wrapper">
    <el-form ref="brandForm" :model="form" label-width="100px">
      <div
        style="
          width: 100%;
          display: flex;
          align-items: flex-end;
          border-bottom: 1px #eee solid;
          margin-bottom: 20px;
        "
      >
        <span style="font-size: 18px; color: #409eff; margin: 10px 0"
          >基本信息</span
        >
      </div>
      <el-form-item
        label="广告位名"
        :rules="{ required: true, message: '请输入银行编号', trigger: 'blur' }"
      >
        <el-col :span="12">
          <el-input v-model="form.name" />
        </el-col>
      </el-form-item>

      <el-form-item label="广告位说明">
        <el-col :span="12">
          <el-input
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 4 }"
            placeholder="请输入内容"
            v-model="form.memo"
          >
          </el-input>
      
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-col :span="12">
          <el-button
            type="primary"
            :loading="clicked"
            @click="saveadPositionte('brandForm')"
          >
            &nbsp&nbsp&nbsp&nbsp完 成&nbsp&nbsp&nbsp&nbsp
          </el-button>
        </el-col>
      </el-form-item>
    </el-form>
  </div>
</template>
<style scoped>
.menu-wrapper {
  margin: 15px;
}
/deep/.el-textarea__inner{
      height: 200px;
  }
</style>
<script>
import { EventBus } from "@/api/eventBus";
import utils from "../../utils/utils.js";
import { save } from "@/api/adPosition";
//   import SingleUpload from '@/components/Upload/singleUpload'
export default {
  name: "adPosition-add",
  filters: {},
  components: {
    //   SingleUpload
  },

  data() {
    return {
      clicked: false, // 按钮防双击
      form: {
        memo: "",
        name: "",
      },
    };
  },
  created() {},
  watch: {
    // 路由地址不变的情况下,如果id变化则重新获取数据
    // $route(newVal, oldVal) {
    //   console.log(newVal);
    //   if (newVal.name == "adPosition-add" && newVal.query.id != this.id) {
    //     this.getData();
    //   }
    // },
  },
  methods: {
    saveadPositionte(form) {
      const _this = this;
      this.$refs[form].validate((valid) => {
        if (valid) {
          // 校验表单
          _this.clicked = true;
          save(_this.form)
            .then((response) => {
              console.log(_this.form);
              console.log(response);
              _this.clicked = false;
              EventBus.$emit("adPosition-add", response.data);
              _this.$store
                .dispatch("tagsView/delView", _this.$route)
                .then(({ visitedViews }) => {
                  _this.$router.push({
                    path: "/adPosition/list",
                  });
                }); // 关闭当前tab回到列表
            })
            .catch((error) => {
              _this.clicked = false;
            });
        } else {
          return false;
        }
      });
    },
  },
};
</script>
